﻿@page
@using WebAPI

@model TestModel
@inject Microsoft.Extensions.Configuration.IConfiguration Configuration

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

@*Must be used with StartupEndPointBugTest*@

<script src="~/js/MyJS.js"></script>

<div class="text-center">

    <h1 class="display-4">CORS Test 2</h1>
    @{
        var host1 = Configuration["host1"];
        var hostTest = host1 + "/test";

        var theHost = HttpContext.Request.Host.Value;
        if (!host1.Contains(theHost) && !theHost.Contains("localhost"))
        {
            <text>Test from <a href="@hostTest">@hostTest</a>  or
            <a href="https://localhost:5001/test">https://localhost:5001/test</a>
            </text>
        }
    }

</div>


<div>
    <span id='result'></span>
</div>


<form>
    <p>
        <select asp-for="Number" asp-items="Model.Genres">
        </select>
        <input type="submit" value="Set Controller" />
    </p>
</form>

<ul>
    <li>
        <input type="button" value="PUT test "
               onclick="MyTestCors3( '@Model.Host', '/api/TodoItems' + '@Model.Number' + '/5', 'PUT', true)" />
    </li>

    <li>
        <input type="button" value="Delete test"
               onclick="MyTestCors3( '@Model.Host', '/api/TodoItems' + '@Model.Number' + '/5', 'DELETE', true)" />
    </li>

    <li>
        <input type="button" value="Delete [EnableCors]"
               onclick="MyTestCors3( '@Model.Host', '/api/TodoItems' + '@Model.Number' + '/MyDelete2/5', 'DELETE', true)" />
    </li>

    <li>
        @*GET requires preflight request because of
        "Content-Type": "x-custom-header"*@
        <input type="button" value="GET"
               onclick="MyTestCors3( '@Model.Host', '/api/TodoItems' + '@Model.Number', 'GET', true)" />
    </li>

    <li>
        <input type="button" value="GET [EnableCors]"
               onclick="MyTestCors3( '@Model.Host', '/api/TodoItems' + '@Model.Number' + '/GetTodoItems2', 'GET', true)" />
    </li>

</ul>

